/**
 * Created by Administrator on 2017/7/1 0001.
 */
var fs = require('fs');
var express = require('express');
var multer  = require('multer');
var fs = require('fs');
var AipOcr = require("./src").ocr;
// 设置APPID/AK/SK
var APP_ID = "9832066";
var API_KEY = "hA6tBlIlDSoyILuxkvv6lr2V";
var SECRET_KEY = "A2E5Em1hvjOkCWuvqouWwxG6lHX2suBB";
var client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

var app = express();
var upload = multer({ dest: 'upload/' });

// 单图上传
app.post('/upload', upload.single('logo'), function(req, res, next){
    var file = req.file;
    var image = fs.readFileSync(file.path);
    var base64Img = new Buffer(image).toString('base64');
    client.generalBasic(base64Img).then(function(result) {
        // console.log(shuju.words_result);
        var sjjj = '';
        for (var value in result.words_result){
            sjjj = sjjj + '<p>'+result.words_result[value].words +'</p>';
        };
        res.send(sjjj);
    });
});

app.get('/', function(req, res, next){
    var form = fs.readFileSync('./from.html', {encoding: 'utf8'});

    res.send(form);
});
app.listen(3000);